package ca.etsmtl.log320lab1;

public class CharFrequency implements Comparable<CharFrequency>
{
	protected int _character;
	protected int _frequency;
	protected CharFrequency _leftChild;
	protected CharFrequency _rightChild;
	protected Boolean _isParentNode = false;
	protected  String _encryptionCode = "";
	public CharFrequency(int character, int frequency)
	{
		this._character = character;
		this._frequency = frequency;
	}
	public CharFrequency(int character)
	{
		this(character, 1);
	}
	public CharFrequency(Boolean isParentNode, CharFrequency leftChild, CharFrequency rightChild)
	{
		_isParentNode = isParentNode;
		_leftChild = leftChild;
		_rightChild = rightChild;
		if (rightChild == null)
			_frequency = leftChild.getFrequency();
		else if(leftChild == null)
			_frequency = rightChild.getFrequency();
		else
		_frequency = leftChild.getFrequency() + rightChild.getFrequency();
	}
	@Override
	public int compareTo(CharFrequency o) {		
		return this.getFrequency() - o.getFrequency();
	}
	public int getFrequency()
	{
		return this._frequency;
	}
	public String getEncryptionCode()
	{
		return _encryptionCode;
	}
	public CharFrequency getLeftChild()
	{
		return _leftChild;
	}
	public CharFrequency getRightChild()
	{
		return _rightChild;
	}
	public void setEncryptionCode(String encryptionCode)
	{
		_encryptionCode = encryptionCode;
	}
	public Boolean getIsParentNode()
	{
		return _isParentNode;
	}
}
